package xyz.hujf.base.interrupted;

/**
 * @author Hujf
 * @title: InterruptedTest
 * @date 2021-04-2120:21
 * @description:   线程使用interrupt优雅的退出
 */
public class InterruptedTest {

    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(()->{
            while (!Thread.currentThread().isInterrupted()){
                System.out.println(Thread.currentThread()+" Hello");
            }
            System.out.println("线程A执行完毕");
        });

        thread.start();

        Thread.sleep(1);

        System.out.println("Main thread interrupted thread ");
        thread.interrupt();

        thread.join();
        System.out.println("zz");
    }
}
